﻿using System.Collections.Specialized;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tigera.Network;
using Tigera.T_Definition;
using System.Configuration;



namespace Plugin.NetRiskMgr
{
    public partial class UCRealtimeMonitor : UserControl
    {
        public UCRealtimeMonitor()
        {
            if (!MQClient.Instance.Logined)
            {
                FormLogin form = new FormLogin();

                DialogResult res =  form.ShowDialog(this);
               
            }
            InitializeComponent();
          
            if (MQClient.Instance.MQConn != null)
            {
                MQClient.Instance.MQConn.MessageReceived += _conn_MessageReceived; 
            }
        }

        public string Title
        {
            get
            {
                return "股票实时监控";
            }
        }
        void ProcessAnyResponse(ref T_AnyObjResponse res)
        {
            switch ((TradeRiskOpe)res.DataType)
            {
                case TradeRiskOpe.ResponseTradeRiskGloStart:
                    {
                        ResponseTradeRiskGloStart ret = ByHelper.DS<ResponseTradeRiskGloStart>(res.Data);
                        MessageBox.Show(this,ret.OpeMessage);
                        break;
                    }
                case TradeRiskOpe.ResponseTradeRiskGloStop:
                    {
                        break;
                    }
                default:
                    break;
                    
            }
        }

        void _conn_MessageReceived(object sender, Tigera.LibCodeUtils.MessageEventArgs e)
        {
            switch ((MessageID)e.Data.TypeID)
            {
                case MessageID.T_AnyObjResponse:
                    {
                        T_AnyObjResponse res =  e.Data.Cast<T_AnyObjResponse>();
                        ProcessAnyResponse(ref res);

                      

                        break;
                    }
                
               
                default:
                    break;
            }

        }

        private void btn_TradeOpe_Click(object sender, EventArgs e)
        {
            TradeCMD cmd = new TradeCMD();
            cmd.Ope = TradeRiskOpe.TradeRiskGloStop;
            btn_TradeOpe.Enabled = false;
            
            MQClient.Instance.MQConn.SendDataTo(MQClient.Instance.MainExchange,ESHelper.Pack(ref cmd));
            
            
           
        }

        private void btn_PosQuery_Click(object sender, EventArgs e)
        {
            TradeCMD cmd = new TradeCMD();
            cmd.Ope = TradeRiskOpe.TradeQueryAccountInfoQuery;

            MQClient.Instance.MQConn.SendDataTo(MQClient.Instance.MainExchange, ESHelper.Pack(ref cmd));
            
        }

        
    }
}
